CREATE PROCEDURE szineszek @id1 int,@id2 int ,@id3 int,@FilmID int OUTPUT,@cim varchar(50) OUTPUT ,@kod int
AS

DECLARE @cim2 varchar (40), @filmId2 int
DECLARE C CURSOR FOR
SELECT DISTINCT F.FilmID,F.Cim
FROM Filmek F, Szerepelnek S
where F.FilmID in (
SELECT  FilmID
FROM Szerepelnek S
WHERE  S.SzereploID=@id1
and FilmID in
(SELECT FilmID
FROM Szerepelnek S
WHERE  S.SzereploID=@id2
and FilmID in
(SELECT FilmID
FROM Szerepelnek S
WHERE  S.SzereploID=@id1)))

SET @cim2=''
SET @filmid2=0

OPEN C
FETCH NEXT FROM C INTO @filmid2,@cim2
WHILE  @@FETCH_STATUS=0
BEGIN
IF @kod=@filmid2
BEGIN
SET @cim=@cim2
SET @filmid=@filmid2
END
FETCH NEXT FROM C INTO @filmid2,@cim2
END
CLOSE C
DEALLOCATE C